package com.xiaohei.rabbitmq.six;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import com.xiaohei.rabbitmq.utils.RabbitmqUtils;

import java.nio.charset.StandardCharsets;

/**
 * @author : 王希辰
 */
public class ReceiveLogsDirect01 {
    public static final String EXCHANGE_NAME="direct_logs";
    public static final String QUEUE_NAME="console";
    public static void main(String[] args) throws Exception {
        Channel channel= RabbitmqUtils.getChannel();
        //声明一个交换机
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT);
        //声明一个队列
        channel.queueDeclare(QUEUE_NAME,false,false,false,null);
        channel.queueBind(QUEUE_NAME,EXCHANGE_NAME,"info");
        channel.queueBind(QUEUE_NAME,EXCHANGE_NAME,"warning");

        //接收消息
        DeliverCallback deliverCallback=(consumerTag, message)->{
            System.out.println("ReceiveLogsDirect01控制台打印接收到的消息："+new String(message.getBody(), StandardCharsets.UTF_8));
        };
        //消费者取消消息回调接口
        channel.basicConsume(QUEUE_NAME,true,deliverCallback,consumerTag -> {});
    }

}
